Welcome to Computer Programming

 

Decimal Format

A class that is used to format a number according to your specifications (ie only 2 decimal places).

You need to import java.text.*;

import java.text.*;

Then in your code, you will convert your number to an output String with a specific pattern. Ie if you want two decimal places, you might say:

String outputAvg = new DecimalFormat("#######.##").format(avg);

Now if avg was 237.234562341 the outputAvg would be 237.23

Note: it does not round, but cuts off.

See this page for other formatting options.